# -*- coding: utf-8 -*-

from hbcxx.simcxx_exp import *


def simcxx_convert_func_task(node_name: str, ir_task: ITask):
    # Convert the body.
    task_body = simcxx_convert_body(ir_task.body)
    # Add indent.
    for ii in range(len(task_body)):
        task_body[ii] = CXX_INDENT + task_body[ii]
    # Construct the task.
    cpp_body = ['void {}::{}()'.format(node_name, ir_task.name),
                '{',
                *task_body,
                '}']
    return '\n'.join(cpp_body)


def simcxx_convert_func_initial(node_name: str, params: str, ir_body: IOpBody):
    # Convert the body.
    init_body = simcxx_convert_body(ir_body)
    # Add indent.
    for ii in range(len(init_body)):
        init_body[ii] = CXX_INDENT + init_body[ii]
    # Construct the node cpp.
    cpp_body = ['{}::{}({}) :'.format(node_name, node_name, params),
                CXX_INDENT + 'Node(parent)',
                '{',
                *init_body,
                '}']
    return '\n'.join(cpp_body)